home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 52
/
Amiga Format AFCD52 (Issue 136, May 2000).iso
/
-in_the_mag-
/
program_perfection
/
arexx
/
arexx_demo.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-03-14
|
3KB
|
171 lines
/*
* Quick Reaction ARexx demo
*
* Richard Drummond 11/3/2000
*
* This code doesn't work :(
* For some reason, it won't create an ARexx object
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <reaction/reaction.h>
#include <classes/arexx.h>
#include <proto/arexx.h>
/*
* Our hostname
*/
#define HOSTNAME "MY_HOSTNAME"
/*
* Prototype for ARexx handler
*/
__saveds VOID HandleARexx( __reg("a0") struct ARexxCmd *, __reg("a1") struct RexxMsg * );
/*
* IDs for out commands
*/
enum
{
REXXID_LOAD,
REXXID_QUIT,
REXXID_MAX
};
/*
* Internal list of commands
*/
struct MyCmd
{
STRPTR Command;
STRPTR Template;
UWORD ID;
};
static CONST struct MyCmd MyCmdTable[ REXXID_MAX ] =
{
"LOAD", "FILE", REXXID_LOAD,
"QUIT", "", REXXID_QUIT
};
/*
* BuildARexxTable
*
* Allocates an ArexxCmd table for passing to the arexx.class from
* the internatl list of commands
*/
struct ARexxCmd *
BuildARexxTable( CONST struct MyCmd *my_table, ULONG cmd_count )
{
struct ARexxCmd *arexx_table;
struct ARexxCmd *table_entry;
if( arexx_table = table_entry = (struct ARexxCmd *) AllocVec( (cmd_count+1) * sizeof(struct ARexxCmd), MEMF_PUBLIC | MEMF_CLEAR ) )
{
do
{
cmd_count--;
table_entry->ac_Name = my_table->Command;
table_entry->ac_ID = my_table->ID;
table_entry->ac_Func = HandleARexx;
table_entry->ac_ArgTemplate = my_table->Template;
table_entry++;
my_table++;
} while( cmd_count );
}
return arexx_table;
}
/*
* Free said table
*/
VOID
FreeARexxTable( struct ARexxCmd *table )
{
FreeVec( table );
return;
}
/*
* Main
*/
int
main( void )
{
struct ARexxCmd *cmds;
Object *arexx;
if( cmds = BuildARexxTable( &MyCmdTable[0], REXXID_MAX ) )
{
ULONG rexx_err = 0L;
/*
* This should create our ARexx port . . .
*/
if( arexx = (Object *) NewObject( NULL, AREXX_GetClass(),
AREXX_HostName, HOSTNAME,
AREXX_NoSlot, FALSE,
AREXX_Commands, cmds,
AREXX_ErrorCode, &rexx_err,
TAG_DONE ) )
{
Printf( "Successful\n" );
/*
* Carry on with the rest . . .
*/
DisposeObject( arexx );
}
else
{
/*
* But it doesn't work . .
*
* It doesn't even return an error.
*
* Hmmmm . . . .
*/
Printf( "DOS Error:%ld\n", IoErr() );
Printf( "ARExx Error:%ld\n", rexx_err );
}
FreeARexxTable( cmds );
}
return 0L;
}
/*
* This a clall-back hook which is called by arexx.class when it receives
* an ARexx message
*
* cmd = the entry in the command table correspondinhg to this command
* rm = the message itself
*/
__saveds VOID
HandleARexx( __reg("a0") struct ARexxCmd *cmd, __reg("a1") struct RexxMsg *rm )
{
/*
* Handle ARexx command here . . .
*/
return;
}